package com.niguang.work.api.entity;

import com.baomidou.mybatisplus.activerecord.Model;
import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.annotations.TableLogic;
import com.baomidou.mybatisplus.annotations.TableName;
import com.baomidou.mybatisplus.enums.FieldFill;
import com.baomidou.mybatisplus.enums.IdType;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.niguang.work.api.enums.ReformRoleTypeEnum;
import lombok.Data;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import java.io.Serializable;
import java.util.Date;

/**
 * <p>
 * 'work.v_personSite' is not BASE TABLE
 * </p>
 *
 * @author chenliu
 * @since 2018-07-23
 */
@TableName("work_wechat_user")
@Data
public class WechatUser extends Model<WechatUser> {

    private static final long serialVersionUID = 1L;

    @TableId(value = "id", type = IdType.AUTO)
    private Long id;
    /**
     * 电话号码
     */
    @NotNull(message = "电话号码不能为空！")
    @Pattern(regexp = "(\\+\\d+)?(\\d{3,4}\\-?)?\\d{7,8}$", message = "手机号码格式不正确！")
    private String userPhone;
    /**
     * 用户姓名
     */
    private String userName;
    /**
     * 用户ID
     */
    private String userId;
    /**
     * 微信ID
     */
    @NotNull(message = "微信openId不能为空！")
    private String openId;
    /**
     * 微信头像
     */
    private String wechatPic;
    /**
     * 微信昵称
     */
    private String wechatNick;
    @TableLogic
    private Integer delFlag;
    @TableField(fill = FieldFill.INSERT)
    private Date createTime;

    /**
     * 微信 unionid
     */
    private String unionId;

    /**
     * 短信验证码
     */
    @JsonIgnore
    private transient String smsCode;

    /**
     * 审核角色
     * 1--整改人 2--审核人
     */
    @TableField(exist = false)
    private Integer roleType;

    @TableField(exist = false)
    private String roleTypeText;

    @TableField(exist = false)
    private String jobPosition;


    public String getRoleTypeText() {
        return ReformRoleTypeEnum.getName(roleType);
    }

    public WechatUser() {
    }

    public WechatUser(String userPhone) {
        this.userPhone = userPhone;
        this.delFlag = 0;
    }

    public static final String ID = "id";

    public static final String USER_PHONE = "user_phone";

    public static final String USER_NAME = "user_name";

    public static final String USER_ID = "user_id";

    public static final String OPEN_ID = "open_id";

    public static final String WECHAT_PIC = "wechat_pic";

    public static final String WECHAT_NICK = "wechat_nick";

    public static final String DEL_FLAG = "del_flag";

    public static final String CREATE_TIME = "create_time";

    public static final String UNION_ID = "union_id";

    @Override
    protected Serializable pkVal() {
        return this.id;
    }

}
